using UnityEngine;

public class Flip : MonoBehaviour
{
    [SerializeField] private Vector3 direction;
    [SerializeField] private float rotationSpeed = 10f;
    
    private Quaternion targetRotation;

    private void Start()
    {
        targetRotation = transform.rotation;
    }

    private void Update()
    {
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
    }

    private void RotationAxis()
    {
        if (direction.x < 0f)
        {
            targetRotation = Quaternion.Euler(0, -90, 0);
        }
        else if (direction.x > 0f)
        {
            targetRotation = Quaternion.Euler(0, 90, 0);
        }
        else if (direction.z > 0f)
        {
            targetRotation = Quaternion.Euler(0, 0, 0);
        }
        else if (direction.z < 0f)
        {
            targetRotation = Quaternion.Euler(0, 180, 0);
        }
    }

    #region Setter
    public void SetDirection(Vector3 dir)
    {
        direction = dir;
        RotationAxis();
    }
    #endregion

    #region Getter
    public Vector3 GetDirection()
    {
        return direction;
    }
    #endregion
}
